package concurrencyPractice.chapter04;

import concurrencyPractice.ThreadSafe;

import java.util.Vector;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 程序4-13 扩展Vector并增加一个若没有就增加的方法
 * @date 2023/12/29 15:06:47
 */
@ThreadSafe
public class BetterVector<E> extends Vector<E> {
    public synchronized boolean putIfAbsent(E x) {
        boolean absent = !contains(x);

        if(absent) {
            add(x);
        }
        return absent;
    }
}
